ActiveAdmin.register Log do

    actions :all, :except => [:new, :edit]

    index do
        column :scan
        column :profile
        column :data
        column(t("scans.form.created")){|log|
          now = Time.now
          created = log.created_at

          time = now - created
          created_at = (time.to_i / 60)

          if created_at >= 60
            if created_at >= 60 and created_at < 120 
              created_at = (created_at.to_i / 60).to_s + " hour ago"
            elsif created_at >= 1440
              created_at = (created_at.to_i / 1440).to_s + " days ago"
            else
              created_at = (created_at.to_i / 60).to_s + " hours ago"
            end
          else
            created_at = created_at.to_i.to_s + " minutes ago"
          end

          created_at
        }


    end
    
    controller do
      def get_logs
        @logs = Log.where("profile = ?", params[:profile_id]).last
        
        if !@logs.blank?
          render :text => @logs.data
        else
          render :text => "FAIL"
        end
      end
    end
end
